package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class LimitSel {
    public static void main(String[] args) {
        Connection connection = DBUtil.getConnection();
        Scanner in=new Scanner(System.in);
        int pageNo=0,pageSize=0;
        while (pageNo<1 ||pageSize<1){
            System.out.println("请输入页大小和页号：");
            pageSize=in.nextInt();
            pageNo=in.nextInt();
        }
        int start=(pageNo-1)*pageSize;
        PreparedStatement ps =null;
        ResultSet rs=null;
        String sql="select stuno,sname as xingming,telephone,enterdate from s_student order by stuno desc limit ?,?";
        System.out.println(sql);
        try {
            ps=connection.prepareStatement(sql);
            ps.setInt(1,start);
            ps.setInt(2,pageSize);

            rs=ps.executeQuery();

            while (rs.next()){
                System.out.println(rs.getLong("stuno"));
                System.out.println(rs.getString("xingming"));
                System.out.println(rs.getDate("enterdate"));
                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(connection,ps,rs);
        }

    }
}
